<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     pagizer
 * @subpackage  website
 */

class m_website_actions_block_DeleteMenuAction extends m_backoffice_extends_FormModal
{
	public function execute()
	{
		$menu = f_document_Provider::getInstance()->getByModelAndUniqueId('website/Menu', $this->getRequestParameter("docId"), $this->getRequestParameter("docLang"));
		
		$messages = array();
		
		$disableDeletion = false;
		if(!is_null($menu->getIndexMenu()))
		{
            $messages[] = $this->getLocale('website.errors.indexMenu', null, array('menuLabel' => $menu->getIndexMenu()->getLabel()));
			$disableDeletion = true;
		}
		else
		{
			$messages[] = $this->getLocale('website.errors.elementsInMenu');
			
			if(count($menu->getAllLangs()) > 1 && !$menu->isATranslation())
			{
				$messages[] = $this->getLocale('website.errors.translatedMenu');
			}
		}

		$this->addToModel("disableDeletion", $disableDeletion);
		$this->addToModel("messages", $messages);
		$this->addToModel("menu", $menu);
		$this->addToModel("href", $this->getRequestParameter("href"));
		
		$this->setView('success');
	}	
	
	public function validate()
	{
		return $this->getUserContext()->hasRight(array("backoffice_accessBo", "website_Delete"));
	}
}